# Esta clase maneja los curriculums cargados para los OGX Trainees. Permite buscar ogxtrainees a partir de tags en los mismos.
class OgxcurriculumsController < ApplicationController

  before_filter :get_mod_cv, :only => [:new, :edit, :delete]

# Recupera todos los cv para ser mostrados en pantalla.
  def index
    @ogxcurriculums = Ogxcurriculum.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @ogxcurriculums }
    end
  end

  # Recupera el cv que va a ser mostrado en pantalla.
  def show
    @ogxcurriculum = Ogxcurriculum.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @ogxcurriculum }
    end
  end


# Prepara el nuevo cv para su posterior creación efectiva.
  def new
    @ogxcurriculum = Ogxcurriculum.new
    @ogxtrainee = Ogxtrainee.find(params[:ogxtrainee_id])
    @ogxtrainee.ogxcurriculum = @ogxcurriculum
  
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @ogxcurriculum }
    end
  end

   # Recupera el cv que va a ser editado.
  def edit
    @ogxcurriculum = Ogxcurriculum.find(params[:id])
  end

# Crea el curriculum.
  def create
    @ogxcurriculum = Ogxcurriculum.new(params[:ogxcurriculum])
    @ogxtrainee.ogxcurriculum.build
   
    respond_to do |format|
      if @ogxcurriculum.save
        flash[:notice] = 'Curriculum was successfully created.'
        format.html { redirect_to(@ogxcurriculum) }
        format.xml  { render :xml => @ogxcurriculum, :status => :created, :location => @ogxcurriculum }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @ogxcurriculum.errors, :status => :unprocessable_entity }
      end
    end
  end

  # Actualiza el curriculum.
  def update
    @ogxcurriculum = Ogxcurriculum.find(params[:id])

    respond_to do |format|
      if @ogxcurriculum.update_attributes(params[:ogxcurriculum])
        flash[:notice] = 'Curriculum was successfully updated.'
        format.html { redirect_to(@ogxcurriculum) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @ogxcurriculum.errors, :status => :unprocessable_entity }
      end
    end
  end

# Borrar efectivamente el curriculum.
  def destroy
    @ogxcurriculum = Ogxcurriculum.find(params[:id])
    @ogxcurriculum.destroy

    respond_to do |format|
      format.html { redirect_to(ogxcurriculums_url) }
      format.xml  { head :ok }
    end
  end
end
